22A - Second Order Statistics - CodeForces Solution


brute force *800

Please click on ads to support us..

Python Code:

n=int(input())
a=list(map(int,input().split()))
s=sorted(list(set(a)))
if len(s)<=1:
    print("NO")
else:
    print(s[1])

C++ Code:

#include <cstdio>

int main(){

    int temp(0), currentMin(101), secondMin(101);
    int n; scanf("%d", &n);

    while(n--){
        scanf("%d", &temp);
        if(temp < currentMin){secondMin = currentMin; currentMin = temp;}
        else if (currentMin < temp && temp < secondMin){secondMin = temp;}
    }

    if(secondMin == currentMin || secondMin == 101){puts("NO");}
    else{printf("%d\n", secondMin);}

    return 0;
}


Comments

Submit
0 Comments
More Questions

137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble
6A - Triangle
1729A - Two Elevators
1729B - Decode String
1729C - Jumping on Tiles
1729E - Guess the Cycle Size
553B - Kyoya and Permutation
1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park
342A - Xenia and Divisors
1033A - King Escape
39D - Cubical Planet
1453A - Cancel the Trains
645A - Amity Assessment
1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring
630N - Forecast
312B - Archer
34D - Road Map
630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya
137B - Permutation